package com.lemon.smartsafetynew.ui.adapter.task;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.util.TimeUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.TimeUtil;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolGetTaskBo;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolTaskVo;
import com.lemon.smartsafetynew.entity.task.InspectionVo;
import com.lemon.smartsafetynew.ui.adapter.patrol.PatrolTaskListAdapter;
import com.lemon.smartsafetynew.ui.fragment.task.InspectionTaskFragment;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/8.
 */

public class InspectionTaskItemAdapter extends LemonRcvAdapter<InspectionVo> {
    private RecyclerTClickListener<InspectionVo> mListener;

    public InspectionTaskItemAdapter(@Nullable List<InspectionVo> data,
                                 RecyclerTClickListener<InspectionVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new InspectionTaskItem();
    }

    private class InspectionTaskItem implements AdapterItem<InspectionVo> {

        private InspectionVo mData;
        private int mPosition;

        private TextView tv_inspection_type;
        private TextView tv_task_time;
        private LinearLayout linearLayoutTask;
        private TextView tv_task_people;
        private TextView tv_task_result;
        @Override
        public int getLayoutResId() {
            return R.layout.item_inspection_task;
        }

        @Override
        public void bindViews(View root) {
            linearLayoutTask = (LinearLayout) root.findViewById(R.id.linear_layout_task);
            tv_inspection_type = (TextView) root.findViewById(R.id.tv_inspection_type);
            tv_task_time = (TextView) root.findViewById(R.id.tv_task_time);
            tv_task_people = (TextView) root.findViewById(R.id.tv_task_people);
            tv_task_result = (TextView) root.findViewById(R.id.tv_task_result);
        }

        @Override
        public void setViews() {
            linearLayoutTask.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(InspectionVo inspectionVo, int position) {
            mData = inspectionVo;
            mPosition = position;
            tv_inspection_type.setText(CommonUtil.avoidNullString(inspectionVo.getTaskName()));
            tv_task_time.setText("任务时间段: "+CommonUtil.avoidNullString(inspectionVo.getStartDateStr())
                    + " ~ " + CommonUtil.avoidNullString(inspectionVo.getEndDateStr()));
            tv_task_people.setText("巡查人员: "+CommonUtil.avoidNullString(inspectionVo.getTaskUserNames()));
            String html = "巡查结果: 正常 "+"<font color='#759f57'>"+inspectionVo.getNormal()+" "
                        +"</font>"+"  异常 "+"<font color='#FF526F'>"+inspectionVo.getAbnormal()+" "+"</font>"+"  未检查 "+"<font color='#86C1FC'>"
                        +inspectionVo.getNocheck()+"</font>";
            tv_task_result.setText(Html.fromHtml(html));
        }
    }
}
